package com.hessian.client;

import java.net.MalformedURLException;

import org.springframework.remoting.caucho.HessianProxyFactoryBean;

import com.caucho.hessian.client.HessianProxyFactory;
import com.hessian.service.IHello;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class HessianTest {

//	private static HessianProxyFactoryBean helloService;
//	
//	public void setHelloService(HessianProxyFactoryBean helloService){
//		this.helloService=helloService;
//	}
	public static IHello hello;
	/**
	 * @param args
	 * @throws MalformedURLException 
	 * @throws MalformedURLException 
	 */
	public static void main(String[] args) throws MalformedURLException{
		// TODO Auto-generated method stub
		//servlet的访问路径
//        commonTest();
		springTest();
        
//        commonTest();
	}
	private static void springTest() {
		ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext-beans.xml");
//		helloService=(HessianProxyFactoryBean) context.getBean("helloService");
        hello=(IHello) context.getBean("helloService");
        System.out.println(hello.greeting("michaellou"));
	}

	private static void commonTest() throws MalformedURLException {
		String url="http://www.michaellou.com:8080/hessian/";
        //创建一HessianProxyFactory对象,用法与xfire很像
        HessianProxyFactory proxyFactory=new HessianProxyFactory();
        //获得HelloWorld的实例,传递两个参数依次为:接口.class,该servlet的访问路径
        IHello hello=(IHello) proxyFactory.create(IHello.class, url);
        System.out.println(hello.greeting("张三"));
	}

}
